package org.baygo.view.api.impl;

import org.baygo.view.api.FrameInterface;
import org.baygo.view.api.util.FrameUtil;

import javax.swing.*;
import java.awt.*;

public class MyJframeCreator implements FrameInterface{

	public JFrame createFrame(JPanel head, JScrollPane center, JScrollPane down, String title) {
		JFrame frame = new JFrame();
		frame.setVisible(true);
		frame.setTitle(title);
		JPanel mainPanel = new JPanel();
		center.setPreferredSize(new Dimension(200, 200));
		head.setBorder(BorderFactory.createTitledBorder("连接"));
		center.setBorder(BorderFactory.createTitledBorder("列表"));
		down.setBorder(BorderFactory.createTitledBorder("日志"));
		setFrameLayout(mainPanel, head, center, down);
		frame.add(mainPanel);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//		frame.setResizable(false);
		FrameUtil.centerView(frame);
		return frame;
	}

	private void setFrameLayout(JPanel mainPanel, JPanel head, JScrollPane center, JScrollPane down){
		GroupLayout layout = new GroupLayout(mainPanel);
		mainPanel.setLayout(layout);

		GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();

		hGroup.addGroup(layout.createParallelGroup().addComponent(head).addComponent(center).addComponent(down));
		layout.setHorizontalGroup(hGroup);

		GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
		vGroup.addGroup(layout.createParallelGroup().addComponent(head));
		vGroup.addGroup(layout.createParallelGroup().addComponent(center));
		vGroup.addGroup(layout.createParallelGroup().addComponent(down));
		layout.setVerticalGroup(vGroup);
		
	}
}